<?php
/******************************************************
v4 - Management Framework
Copyright (C) 2008  Gary Taylor, gMerc Incorporation
http://www.gmerc.com/v4/

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

gary@gmerc.com
******************************************************/
class editpersonnelgroups {
  function loaddata() {
    global $masterclass;

    $masterclass->loadfunctions('personnel');

    $personnellist=$masterclass->allclasses['personnel_func']->fetch_personnellist();
    $personnelgroupmembers='';
    if (!empty($personnellist)) {
      foreach ($personnellist as $pl) {
        if ($masterclass->sitevars['personnelgroupmember'.$pl['id']]!='') { if ($personnelgroupmembers!='') { $personnelgroupmembers.=','; } $personnelgroupmembers.=$pl['id']; }
      }
    }

    $masterclass->site['postfields'][] = array(
      'table'=>'personnelgroups',
      'trackingid'=>'personnelgroupid',
      'fields'=>array(
        'active'=>'personnel_active',
        'name'=>'personnel_groupname'
      ),
      'static'=>array(
        'members'=>','.$personnelgroupmembers.','
      )
    );

    $masterclass->websiteconfig['title']='Edit Personnel Group: '.$masterclass->allclasses['personnel_func']->fetch_personnelgroupname($masterclass->sitevars['personnelgroupid']);

  return;
  }

  function display() {
  global $masterclass;

?>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top">
    <td>
<?php
  echo $masterclass->allclasses['websites']->sitebox_pageheader($masterclass->sitevars['personnel_groupname'].' ['.$masterclass->sitevars['personnelgroupid'].']','');

  $nav='';
  $nav.='<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr valign="middle" class="sitebox_navigation">';
  $nav.='<td>Navigate Groups:&nbsp;&nbsp;</td>';
  $querystring=$masterclass->trackingvar_query();
  $nav.='<td><input type="submit" value="Save" class="button" OnClick="hide(document.getElementById(\'maincontainer\'));show(document.getElementById(\'loadingcontainer\'));">&nbsp;&nbsp;&nbsp;<input type="button" class="button" value="Close" OnClick="closewindow();"></td>';
  $nav.='<td><input type="button" value="Delete Personnel Group"></td>';
  $nav.='</tr></table>';
  echo $masterclass->allclasses['websites']->sitebox_navigation($nav);
?>
  </td>
  </tr>
</table>
<table width="100%" cellpadding="2" cellspacing="5" border="0">
  <tr valign="top">
  <td width="40%">
<?php
/* Start Window */
  echo $masterclass->allclasses['websites']->sitebox_start('100%');
  echo $masterclass->allclasses['websites']->sitebox_headline('Group Information','');
?>
<table width="100%" align="center" cellpadding="0" cellspacing="1" class="sitebox_content">
  <tr valign="bottom">
    <td width="50" valign="middle" style="padding-left:2px;text-align:right;"><nobr>Name:&nbsp;</nobr></td>
    <td width="95%"><nobr><input type="text" value="<?php echo $masterclass->displayhtmlvalue($masterclass->sitevars['personnel_groupname']); ?>" name="personnel_groupname" id="personnel_groupname" size="25" maxlength="190" align="absmiddle"></nobr></td>
  </tr>
</table>
<?php
  echo $masterclass->allclasses['websites']->sitebox_end();
/* End Window */

echo $masterclass->allclasses['websites']->sitebox_vspacer();

/* Start Window */
  echo $masterclass->allclasses['websites']->sitebox_start('100%');
  echo $masterclass->allclasses['websites']->sitebox_headline('Group Members','');

  $personnellist=$masterclass->allclasses['personnel_func']->fetch_personnellist();
  $arrmembers=$masterclass->allclasses['personnel_func']->fetch_personnelgroupmembers($masterclass->sitevars['personnelgroupid']);
?>
<table width="100%" align="center" cellpadding="0" cellspacing="1" class="sitebox_content"><tr valign="top">
<?php
  if (!empty($personnellist)) {
    $recordid=0;
    $recordcnt=count($personnellist);
    foreach ($personnellist as $pl) {
    if ($recordid==0 || $recordid==(ceil($recordcnt/2))) {  ?><td width="50%"><table width="100%" align="center" cellpadding="0" cellspacing="0" class="sitebox_content"><?php }
?>
  <tr valign="middle">
    <td align="middle" width="20" style="padding-left:2px;text-align:right;"><input type="checkbox" name="personnelgroupmember<?php echo $pl['id'];?>" id="personnelgroupmember<?php echo $pl['id'];?>" value="<?php echo $pl['id'];?>" <?php if (!empty($arrmembers) && in_array($pl['id'],$arrmembers)) { echo ' checked '; }?>></td>
    <td ><nobr><?php echo $masterclass->displayhtmlvalue($pl['first'].' '.$pl['last']); ?></nobr></td>
    <td ><nobr><?php echo $masterclass->displayhtmlvalue($pl['location']); ?></nobr></td>
    <td ><nobr><?php echo $masterclass->displayhtmlvalue($pl['team'].'/'.$pl['subteam']); ?></nobr></td>
    <td ><nobr><?php echo $masterclass->displayhtmlvalue($pl['title'].'-'.$pl['department']); ?></nobr></td>
  </tr>
<?php
    if ($recordid==($recordcnt-1) || $recordid==(ceil($recordcnt/2)-1)) { ?></table></td><?php }
    $recordid+=1;
    }
  } else {
?>
    <td><nobr>No Personnel</nobr></td>
<?php
  }
?>
</tr></table>
<?php
  echo $masterclass->allclasses['websites']->sitebox_end();
/* End Window */
?>
</td></tr></table>
<?php

  return;
  }
}
?>